package org.java.web;

import com.alibaba.fastjson.JSON;
import org.java.dao.managerUserDao;
import org.junit.Test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author :王特
 * @create: 2022/02/24 9:37
 */
@WebServlet("/ajax")
public class ajaxSevlet extends BaseServlet{
    private  managerUserDao managerUserDao=new managerUserDao();


	protected void init(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("进入");
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		Integer countLogin= managerUserDao.login(username,password);
		System.out.println("查询到的数量为："+countLogin);
		HttpSession session = request.getSession();
		if (countLogin.equals(1)){


			session.setAttribute("login", countLogin);
		}else {
			session.setAttribute("login",0);
		}
		Map map = new HashMap();

		map.put("countLogin",countLogin);//数据

		map.put("code",0);//正确

		map.put("msg","");//错误消息

		map.put("count",600);//数据总数


		String json = JSON.toJSONString(map);

		response.setContentType("text/html;charset=utf-8");


		PrintWriter out = response.getWriter();
		out.write(json);
		out.flush();
		out.close();
	}

}
